<template>
    <!-- 修改资料 -->
  
    <div>
      <el-form
        label-width="85px"
        :model="form"
        label-position="right"
        ref="formRef"
        :rules="formRules"
      >
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="编号" prop="number">
              <el-input v-model="form.number"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="最小金额" >
                <el-input v-model="form.minReward" type="number"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="最大金额" >
                <el-input v-model="form.maxReward" type="number"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="顺序" prop="areaLevel">
              <el-input
                v-model="form.areaLevel"
                clearable
                placeholder="请选择："
                type="number"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="赠送积分" prop="rewardPoint">
              <el-input
                v-model="form.rewardPoint"
                clearable
                placeholder="请选择："
                type="number"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="允许注册">
              <el-switch
                v-model="form.allowRegiste"
                inline-prompt
                :active-icon="Check"
                :inactive-icon="Close"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="状态" prop="status">
              <el-switch
                v-model="form.status"
                inline-prompt
                :active-icon="Check"
                :inactive-icon="Close"
                active-value="normal"
                inactive-value="disable"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="button-position">
        <el-button @click="updateVisible">取 消</el-button>
        <el-button type="primary" @click="addMemberlevel(formRef)">确 定</el-button>
      </div>
    </div>
  </template>
    
  <script setup>
  import { reactive, ref, watch, onMounted } from "vue";
  import { ElNotification } from "element-plus";
  import { Check, Close } from "@element-plus/icons-vue";
  import Api from "@/api/model/crm";
  import tsMap from '@/components/tsMap/index.vue'
  const emit = defineEmits(["updatetable"]);
  onMounted(() => {
    getInit();
  });
  
  const props = defineProps({
    paramsData: {
      type: Object,
      defalut: {},
    },
  });
  
  // 添加用户数据的对象
  const form = ref({});
  const configData = ref({});
  const formRef = ref();
  const formRules = reactive({
    number: [{ required: true, message: "请输入编号", trigger: "blur" }],
    name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  });
  
  const updateVisible = (val) => {
    emit("updatetable");
  };
  
  const getInit = async () => {

    let res = await Api.rewardset.add.post()
    if(res.code == '200'){
        form.value = res.data
    }
  };
  
  const restAddFormData = () => {
    formRef.value.resetFields();
  };
  
  // 上传
  const addMemberlevel = async (formRef) => {
    await formRef.validate((valid, fields) => {
      if (valid) {
        addMemberlevelData();
      }
    });
  };
  
  const addMemberlevelData = async () => {
    form.value.transactionKind = '0'
    var params = {
      bean: form.value,
    };
    var res = await Api.rewardset.save.post(params);
    if (res.code == 200) {
      restAddFormData();
      ElNotification.success({
        title: "",
        message: "添加成功！",
        duration: 2000,
      });
      emit("updatetable", true);
    }
  };
  </script>
    
  <style scoped lang="less">
  .borderNone {
    :deep(.el-input__wrapper) {
      box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color))
        inset;
      cursor: default;
      background-color: transparent;
      border-bottom: 1px solid #999;
      border-radius: 0;
  
      .el-input__inner {
        cursor: default !important;
      }
    }
  }
  </style>
    
    